﻿using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace YY.Admin.Core.Converter
{
    /// <summary>
    /// 将枚举值转换为Visibility
    /// </summary>
    public class EnumToVisibilityConverter : IValueConverter
    {
        /// <summary>
        /// 将枚举值转换为 Visibility
        /// </summary>
        /// <param name="value">绑定的枚举值</param>
        /// <param name="targetType"></param>
        /// <param name="parameter">ConverterParameter 指定要匹配的枚举值</param>
        /// <param name="culture"></param>
        /// <returns>匹配返回Visible</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return Visibility.Collapsed;

            return value.ToString()!.Equals(parameter.ToString(), StringComparison.OrdinalIgnoreCase)
                ? Visibility.Visible
                : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        => throw new NotImplementedException();
    }
}
